import time
from selenium.webdriver import Edge
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

web = Edge()

web.get("https://www.lagou.com/")

# 找到某个元素，点击他
el = web.find_element(By.XPATH, '//*[@id="changeCityBox"]/p[1]/a')
el.click()  # 找到标签，点击事件

# 点击完最好让页面加载出来
time.sleep(1)  # 让浏览器缓一会

# 找到输入的框输入python,再回车
# 回车导包：from selenium.webdriver.common.keys import Keys
inp = web.find_element(By.XPATH, '//*[@id="search_input"]')
inp.send_keys("python", Keys.ENTER)

time.sleep(1)  # 浏览器加载

# //*[@id="jobList"]/div[1]/div[1]   这里div[1]改成div，取所有的div对象
# //*[@id="jobList"]/div[1]/div[4]/div[1]/div[1]/div[1]/a
# //*[@id="jobList"]/div[1]/div[2]/div[1]/div[1]/div[2]
# //*[@id="jobList"]/div[1]/div[2]/div[1]/div[1]/div[2]/span
div_list = web.find_elements(By.XPATH, '//*[@id="jobList"]/div[1]/div')  # 注意div
for div in div_list:
    # 每个div下对应的数据
    name = div.find_element(By.XPATH, './div[1]/div[1]/div[1]/a').text
    req = div.find_element(By.XPATH, './div[1]/div[1]/div[2]').text

    print(name, req)

time.sleep(100)
